function [out] = deslant(in)
[m,n] = size(in);
[x,y] = meshgrid(1:n,1:m);

w = in(:);
w = w/sum(w);
ux = w'*x(:);
uy = w'*y(:);
sx = x(:)-ux;
sy = y(:)-uy;
ixx = w'*(sx.*sx);
iyy = w'*(sy.*sy);
ixy = w'*(sx.*sy);

nx = x(:)-(n+1)/2;
ny = y(:)-(m+1)/2;

nx = nx+ixy*sy/iyy+ux;
ny = ny+uy;

out = zeros(size(in));
ii = find(nx>=1 & nx<=n);
out(ii) = interp2(x,y,in,nx(ii),ny(ii),'linear');
end